package com.champrin.replicationofmyblockapix.activity;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.champrin.replicationofmyblockapix.R;
import com.champrin.replicationofmyblockapix.http.Player;

public class MenuActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        Button newGameBtn = findViewById(R.id.new_game_btn);
        newGameBtn.setOnClickListener(v -> {
            showLevelChooseDialog();
        });

        Button continueGameBtn = findViewById(R.id.continue_game_btn);
        continueGameBtn.setOnClickListener(v -> {
            // 启动游戏视图，继续游戏
            Intent intent = new Intent(MenuActivity.this, GameActivity.class);
            intent.putExtra("message", "continue");

            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        });

        Button checkInfoBtn = findViewById(R.id.check_info_btn);
        checkInfoBtn.setOnClickListener(v -> {
            Player.globolPlayer.showPlayerInfoDialog(new AlertDialog.Builder(this), getLayoutInflater());
        });
    }

    public int chooseLevel = 999;

    public void showLevelChooseDialog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        LayoutInflater inflater = getLayoutInflater();

        View dialogView = inflater.inflate(R.layout.dialog_level_choose_layout, null);
        dialogBuilder.setView(dialogView);

        Button btnLevel1 = dialogView.findViewById(R.id.btn_level1);
        Button btnLevel2 = dialogView.findViewById(R.id.btn_level2);
        Button btnLevel3 = dialogView.findViewById(R.id.btn_level3);
        Button btnExit = dialogView.findViewById(R.id.btn_exit);

        final AlertDialog dialog = dialogBuilder.create();
        // 设置AlertDialog的背景为透明
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCancelable(false);

        btnLevel1.setOnClickListener(v -> {
            // 启动游戏视图，新游戏
            Intent intent = new Intent(MenuActivity.this, GameActivity.class);
            intent.putExtra("message", "create");
            intent.putExtra("level", 1);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            dialog.dismiss();
        });
        btnLevel2.setOnClickListener(v -> {
            Intent intent = new Intent(MenuActivity.this, GameActivity.class);
            intent.putExtra("message", "create");
            intent.putExtra("level", 2);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            dialog.dismiss();
        });
        btnLevel3.setOnClickListener(v -> {
            Intent intent = new Intent(MenuActivity.this, GameActivity.class);
            intent.putExtra("message", "create");
            intent.putExtra("level", 3);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            dialog.dismiss();
        });
        btnExit.setOnClickListener(v -> dialog.dismiss());

        dialog.show();
    }
}